Main site

Built-in Modules > Dsers Class

Dsers Class

Important: This plugin relies on third-party resources. The resources might change or be discontinued without notice. Ensure you test the plugin extensively before production use, implement error handling with a try-catch block, have a backup shipping rate ready, and reach out to our support with detailed descriptions of any unexpected issues.

Overview

The Dsers class is designed to retrieve real-time shipping rates for products managed by Dsers.

Class Definition

class Dsers {
  constructor(dsers_email, dsers_password, destination, currency) {
    // Class constructor
  }

  async getRates(dsersProducts) {
    // Method to fetch rates
  }
}

Arguments

  • dsers_email (String): The email address associated with your Dsers account.
  • dsers_password (String): The password for your Dsers account.
  • destination (Object): The "destination" information from the DATA JSON object used in the calculateShippingRates function.
  • currency (String): The currency ISO code for which shipping rates will be calculated.

Usage Example

const dsers = new Dsers(env.dsers_email, env.dsers_password, DATA.destination, DATA.currency);
const dsersProducts = [
  { dsers_product_id: "2251832577512145", quantity: 1 },
  { dsers_product_id: "1005005661771025", quantity: 2 },
  // ... additional products
];
const rates = await dsers.getRates(dsersProducts);

This example shows how to use the Dsers class by passing account credentials, destination, and currency to the constructor. The getRates method fetches shipping rates for a list of products identified by Dsers product IDs and their quantities. The returned rates will be in the same format as those provided by Shopify. For better security, your Dsers credentials should be saved in the env object as encrypted secret variables in the JsRates Settings page.

Dsers product id

The dsers_product_id is a unique identifier for products sourced from suppliers on Dsers, which corresponds to the product ID on AliExpress when using AliExpress as your supplier platform.

To configure your Dsers account to use the dsers_product_id as the SKU:

  1. Go to the Settings page in your Dsers account.
  2. Under General Settings, select Product.
  3. Enable the Use the supplier ID as product SKU option.

When this option is enabled, Dsers will automatically prepend the dsers_product_id to the variant's name in the SKU field. For instance, if you have a variant named green, and the product ID is 1005005871752711, the SKU will be formatted as 1005005871752711-green. The following sample code fetches a real-time shipping rates for Dsers products using their sku.

If AliExpress is your Dsers supplier platform, you can directly use our AliExpress plug-in without your Dsers credentials. The same product id is used for AliExpress.

Sample AI Prompt

I'd like a shipping rate calculator for items from Dsers.
The Dsers product id is contained as part of the items sku separted with a hyphen. Split the sku and take the first part as Dsers product id.
The Dsers email and password are saved in the environment variable object.

Sample AI Output

import { enrichItemDetails } from "./modules.js";
import { Dsers } from "./modules.js";

export async function calculateShippingRates(DATA, env) {
  try {
    // Enrich items with additional details
    DATA = await enrichItemDetails(DATA);

    // Extract Dsers product IDs from SKUs
    const dsersProducts = DATA.items.map((item) => {
      const [dsersProductId] = item.sku.split("-");
      return { dsers_product_id: dsersProductId, quantity: item.quantity };
    });

    // Create a new Dsers instance
    const dsers = new Dsers(env.dsers_email, env.dsers_password, DATA.destination, DATA.currency);

    // Get shipping rates from Dsers
    const rates = await dsers.getRates(dsersProducts);

    // Return shipping rates in the Shopify format
    return { rates };
  } catch (error) {
    // Return error rate
    return {
      rates: [
        {
          service_name: "",
          service_code: "",
          total_price: null,
          description: "",
          currency: "",
          min_delivery_date: "",
          max_delivery_date: "",
        },
      ],
    };
  }
}